package com.th.switchnet;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import net.lingala.zip4j.core.ZipFile;
import net.lingala.zip4j.exception.ZipException;
import net.lingala.zip4j.model.ZipParameters;
import net.lingala.zip4j.util.Zip4jConstants;

/**
 *
 * @author thduan
 * @date 2015-11-13 上午9:27:56
 */
public class ZFileUtil {
	
	public static void unzip(String zFile, String netV) {
		
	}
	
	public static void testZ(String zFile, String netValue) {
		try {
			ZipFile zipFile = new ZipFile(zFile);
			
			//remove file
//			zipFile.removeFile("ktv.properties");
			//生成新文件
			String newFilePath = AppDefine.CACHE_DIR + "ktv.properties";
			FileOutputStream out = new FileOutputStream(newFilePath);
			out.write(netValue.getBytes());
			out.close();
			
			//add file
			ZipParameters parameters = new ZipParameters();
			parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
			parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
			parameters.setRootFolderInZip("/res/raw");
			zipFile.addFile(new File(newFilePath), parameters);
		} catch (ZipException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		LogUtil.log("替换完成");
		
	}

}
